package com.company.service.impl;

import com.company.dao.UserDao;
import com.company.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @ClassName UserServiceImpl
 * @Description
 */
/*
 <bean id="userService" class="com.company.service.impl.UserServiceImpl">
        <property name="userDao" ref="userDao"></property>
 </bean>
*/
@Service("userService")
public class UserServiceImpl implements UserService {

//    @Autowired
//    @Qualifier("userDao")     // 按照容器的名称，从容器中进行匹配
//    private UserDao userDao;

//    @Resource(name = "userDao")
//    private UserDao userDao;

    // 通过类型，从Spring容器中进行查找，进行配置
    @Autowired
    private UserDao userDao;

    @PostConstruct
    public void myInit(){
        System.out.println("初始化方法~~~");
    }

    @Override
    public void save() {
        System.out.println("UserServiceImpl 进行保存数据 ······ ");
        userDao.save();
    }

    @PreDestroy
    public void myDestroy(){
        System.out.println("销毁方法~~~");
    }
}
